<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    </head>
    <style type="text/css" media="screen">
        .v{
            width: 145px;
            height: 50px;
            border:1px solid #000;
        }
    </style>
    <body>
    <form>
    用户名：<input type="text" name="username" value="" placeholder="">
    密码： <input type="password" name="password" value="" placeholder="">

    <input type="button" name="" value="登录" onclick="login()">
    </form>
    <a href="{:url('Login/res')}">注册</a>
    </body>
    <script type="text/javascript">
    function login(){
    var username=$('input[name=username]');
    var password=$('input[name=password]');

    if(username.val()=="")
    {
        alert("用户名不能为空");
        username.focus();
        return ;
    }

    if(password.val()=="")
    {
        alert("密码不能为空");
        password.focus();
        return ;
    }
    $.post("{:url('Login/login2')}",{username:username.val(),password:password.val()}, function(data) {
        if(data.status==1)
        {
            alert(data.message);
            window.location.href="{:url('User/index')}";
        }
        else
            alert(data.message);
    
    });

}
    </script>
</html>